package com.lighu.computing.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import androidx.annotation.Nullable;

import com.lighu.computing.model.ConstantFields;

/**
 * @Author : LingHu
 * @Email : 1714873054@qq.com
 * @Date : on 2023/10/4 16:50.
 * @Description :
 */
public class DatabaseLaunch extends SQLiteOpenHelper {
    private static final String TAG="DatabaseHelper";
    /**
     *
     * @param context
     */
    //初始化数据库数据
    public DatabaseLaunch(@Nullable Context context) {
        super(context, ConstantFields.DATABASE_NAME, null, ConstantFields.VERSION_CODE);
    }


    /**
     * 第一次创建数据库时会执行它
     * @param db
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
        //创建时的回调
        Log.d(TAG,"创建数据库");
        String sql=
                "create table "+ConstantFields.TABLE_NAME+" (id Integer,name varchar,age Integer,salary Integer)";
        db.execSQL(sql);
    }

    /**
     * 升级数据库时的回调
     * @param
     * @param i
     * @param i1
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int i, int i1) {
        //升级数据库时的回调
        Log.d(TAG,"升级数据库");
    }
}
